import request from '@/utils/request'

export function getRoutes() {
  return request({
    url: '/vue-element-admin/routes',
    method: 'get'
  })
}

export function getRoles() {
  return request({
    url: '/vue-element-admin/roles',
    method: 'get'
  })
}

export function addRole(data) {
  return request({
    url: '/vue-element-admin/role',
    method: 'post',
    data
  })
}

export function updateRole(id, data) {
  return request({
    url: `/vue-element-admin/role/${id}`,
    method: 'put',
    data
  })
}

export function deleteRole(id) {
  return request({
    url: `/vue-element-admin/role/${id}`,
    method: 'delete'
  })
}

// 新增角色
export const SubmitRoleAsync = data => {
  return request({
    url: "/JwtAPI/UserAsync/SubmitRoleAsync",
    method: 'post',
    data
  })
}

// 获取组织角色
export const GetOrgRolesAsync = (params) => {
  return request({
    url: "/JwtAPI/UserAsync/GetOrgRolesAsync",
    method: 'get',
    params: params
  })
}

// 启用/禁用角色
export const DisabledRoleSwitchAsync = data => {
  return request({
    url: "/JwtAPI/UserAsync/DisabledRoleSwitchAsync",
    method: 'post',
    data
  })
}

// 删除角色
export const DelRolesAsync = data => {
  return request({
    url: "/JwtAPI/UserAsync/DelRolesAsync",
    method: 'post',
    data
  })
}

// 根据登录用户组织id 获取后台菜单List
// （根据产品系列-模块-页面-按钮来分级）
export const GetTreeMenusByRoleTwoAsync = (params) => {
  return request({
    url: "/JwtAPI/UserAsync/GetTreeMenusByRoleTwoAsync",
    method: 'get',
    params: params
  })
}

// 为角色权限配置
export const UpdateAuthorityAsync = data => {
  return request({
    url: "/JwtAPI/UserAsync/UpdateAuthorityAsync",
    method: 'post',
    data
  })
}

// 获取组织下全部角色数据 (不分页)
// 如果传了组织ID，则查询指定组织的角色数据。
// 如果没传组织ID，则查询登录人所属组织的角色数据。
export const GetAllRolesAsync = params => {
  return request({
    url: '/JwtAPI/UserAsync/GetAllRolesAsync',
    method: 'get',
    params: params
  })
}
